package com.learn.base.controller;

import com.learn.base.annotation.RedisLock;
import com.learn.base.annotation.SysLog;
import com.learn.base.model.redisson.RedissonReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author : Yu.Tan
 * @date : 2023/1/17 15:17
 * @desc : **
 */
@RestController
@RequestMapping("/learn/redisson/lock")
@Api(tags = "redissonLock测试")
@AllArgsConstructor
public class RedissonLockController {

    public static Integer result=0;

    @ApiOperation("redissonLock测试方法一")
    @PostMapping("/test")
    @RedisLock(lockName = "testLock",key = "#req.orderId+':'+#req.userId")
    public void redissonTest(@RequestBody RedissonReq req){
        System.out.println("测试系统");
    }

    @ApiOperation("redissonLock测试方法二")
    @GetMapping("/test2")
    @RedisLock(lockName = "testLock",key = "#orderId+':'+#userId")
    @SysLog("redissonLock测试方法二")
    public void redissonTest2(@RequestParam("orderId") String orderId,@RequestParam("userId") String userId){

        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        result+=1;
//        System.out.println("测试系统2"+Thread.currentThread().getName());
    }

    @ApiOperation("redissonLock测试方法三")
    @GetMapping("/test3")
    @RedisLock(lockName = "testLock",key = "#orderId")
    public void redissonTest3(@RequestParam("orderId") String orderId){
        System.out.println("测试系统3");
    }

}
